<template>
	<view class="">
		<view class="btn-b flex-align-end">
			<view class=" heji-box">
				<text class="heji">合计：</text>
				<view class="">
					<text class="fuhao">￥</text>
					<text class="jiae">{{props.num}}</text>
				</view>
			</view>
			<view @click="payment" class="blue-btn">{{props.text}}</view>
		</view>


	</view>
</template>

<script setup>
	import {
		ref,
		defineProps,
		onMounted,
		onUpdated
	} from "vue";
	import {
		pay
	} from "../../requestApi/api.js";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	const props = defineProps(['num', 'text', 'detail', 'type'])
	const data = ref({
		form: {
			sourceId: props.detail.id,
			orderType: props.type,
			entrySourceId: '',
			groupId: '',
			ticketUserId: '',
		},
	})
	onMounted(() => {
		// console.log('444', props.detail)
	})
	onUpdated(() => {
		if (props.type == 1) {
			//赛事报名
			data.value.form = {
				sourceId: props.detail.sourceId,
				orderType: props.type,
				entrySourceId: props.detail.entrySourceId,
				groupId: props.detail.groupId,
				ticketUserId: props.detail.ticketUserId
			}
		} else {
			data.value.form = {
				sourceId: props.detail.id,
				orderType: props.type,
			}
		}
		// console.log('555', props.detail)
	})

	const payment = () => {
		console.log(data.value.form)
		pay(data.value.form).then(res => {
			let resData = res.data.jsonObject;
			console.log(resData)
			uni.requestPayment({
				timeStamp: '' + resData.timeStamp,
				nonceStr: resData.nonceStr,
				package: resData.package,
				signType: resData.signType,
				paySign: resData.paySign,
				success(res) {
					// console.log(res);
					if (props.type == 1) {
						//赛事
						uni.reLaunch({
							url: '/pages/tabbar/order/order'
						})
					} else {
						uni.navigateBack(1);
					}

				},
				fail(e) {
					console.log('err:', e);
					uni.showToast({
						icon: 'error',
						title: '支付失败'
					})
				}
			})
		})

	};
</script>

<style lang="scss">
	.heji-box {
		padding-left: 68rpx;

		.heji {
			font-size: 32rpx;
			font-weight: bold;
			color: #2C2C2C;
		}

		.fuhao {
			font-size: 48rpx;
			color: #F26D61;
			font-weight: bold;
			letter-spacing: -4rpx;
		}

		.jiae {
			font-size: 72rpx;
			color: #F26D61;
			letter-spacing: -4rpx;
			font-weight: bold;
			line-height: 80rpx;
		}
	}

	.btn-b {
		padding-bottom: 26rpx;
	}
</style>